package com.myschool.dao.impl;

import com.myschool.dao.SubjectDao;
import com.myschool.pojo.Subject;
import com.myschool.util.BaseDao;

import java.util.List;

public class SubjectDaoImpl implements SubjectDao {
    @Override
    public int add(Subject subject) {
        String sql = "INSERT INTO subject(SubjectNo,Subjectname,classhour,gradeID) values(?,?,?,?)";
        return BaseDao.executeUpdate(sql,subject.getSubjectNo(),subject.getSubjectName(),subject.getClassHour(),subject.getGradeId());
    }

    @Override
    public int deleteSubject(int subjectno) {
        String sql = "delete from subject where subjectno=?;";
        return BaseDao.executeUpdate(sql,subjectno);
    }

    @Override
    public int updateSubject(Subject subject) {
        String sql = "update subject set subjectname = ? where subjectno = ?;";
        return BaseDao.executeUpdate(sql,subject.getSubjectName(),subject.getSubjectNo());
    }

    @Override
    public List showSubject(Class classz) {
        String sql = "select * from"+"  "+classz.getSimpleName();
        return  BaseDao.show(sql,classz);
    }

    @Override
    public List findBySubjectId(int id, Class classz) {
        String sql = "select * from"+"  "+classz.getSimpleName()+"where Subjectno="+id;
        return BaseDao.show(sql,classz,id);
    }
}
